<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <link rel="apple-touch-icon" sizes="76x76" href="/assets/img/apple-icon.png">
    <link rel="icon" type="/image/png" href="/assets/img/favicon.png">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>账号注册</title>
    <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no' name='viewport' />
    <!--     Fonts and icons     -->
    <link href="https://fonts.googleapis.com/css?family=Montserrat:400,700,200" rel="stylesheet" />
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css" />
    <!-- CSS Files -->
    <link href="/assets/css/bootstrap.min.css" rel="stylesheet" />
    <link href="/assets/css/now-ui-kit.css?v=1.1.0" rel="stylesheet" />
    <!-- CSS Just for demo purpose, don't include it in your project -->
    <link href="/assets/css/demo.css" rel="stylesheet" />
    <!-- Canonical SEO -->
    <link rel="canonical" href="" />
    <!--  Social tags      -->
    <meta name="keywords" content="">
    <meta name="description" content="">
    <!--   Core JS Files   -->
    <script src="/assets/js/core/jquery.3.2.1.min.js" type="text/javascript"></script>
    <script src="/assets/js/core/popper.min.js" type="text/javascript"></script>
    <script src="/assets/js/core/bootstrap.min.js" type="text/javascript"></script>
    <!--  Plugin for Switches, full documentation here: http://www.jque.re/plugins/version3/bootstrap.switch/ -->
    <script src="/assets/js/plugins/bootstrap-switch.js"></script>
    <!--  Plugin for the Sliders, full documentation here: http://refreshless.com/nouislider/ -->
    <script src="/assets/js/plugins/nouislider.min.js" type="text/javascript"></script>
    <!--  Plugin for the DatePicker, full documentation here: https://github.com/uxsolutions/bootstrap-datepicker -->
    <script src="/assets/js/plugins/bootstrap-datepicker.js" type="text/javascript"></script>
    <!-- Share Library etc -->
    <script src="/assets/js/plugins/jquery.sharrre.js" type="text/javascript"></script>
    <!-- Control Center for Now Ui Kit: parallax effects, scripts for the example pages etc -->
    <script src="/assets/js/now-ui-kit.js?v=1.1.0" type="text/javascript"></script>
    <script>
        //判断邮箱是否合法的方法
        function ifEmail(){
            var email = $('input[name="email"]').val();
            var zz = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
            if(email==null||email==''||email.length==0){
                $(".modal-body").html("<p>邮箱不能为空</p>");
                $("#msg").modal(true);
                return false;
            }else if(!zz.test(email)){
                $(".modal-body").html("<p>邮箱不合法</p>");
                $("#msg").modal(true);
                return false;
            }else{
                return true;
            }
        }
        /**
         * 倒计时
         * e 代表发送按钮对象
         */
        function resetTime(e){
            var second = 60;
            var timer = null;
            timer = setInterval(function(){
                second -= 1;
                if(second >0){
                    $(e).attr('disabled',true);
                    $(e).text(second + "秒后获取验证码");
                }else{
                    clearInterval(timer);
                    $(e).attr('disabled',false);
                    $(e).text("发送验证码");
                }
            },1000);
        }
        $(function () {
            $('input[name="email"]').blur(function () {
            })
            //获取验证码点击
            $("#getCode").click(function () {
                if(ifEmail()){
                    $.ajax({
                        url:'/sendRegEmail',
                        type:'post',
                        dataType:'json',
                        data:$(".form").serialize(),
                        success:function (data) {
                            if(data.state==1){
                                $(".modal-body").html("<p>验证码发送成功，请注意您的邮箱</p>");
                                resetTime($("#getCode"));
                                $("#msg").modal(true);
                            }else{
                                $(".modal-body").html("<p>该邮箱已经被使用,或者该邮箱不合法，请更换邮箱</p>");
                                $("#msg").modal(true);
                            }
                            return false;
                        }
                    });
                }
            })
            //注册按钮点击
            $("#reg").click(function () {
                if($('input[name="realname"]').val().length>0&&$('input[name="password"]').val().length>0){
                    if($('input[name="code"]').val().length>0){
                        if($('input[name="code"]').val().length>0){
                            $.ajax({
                                url:'/reg',
                                type:'post',
                                dataType:'json',
                                data:$(".form").serialize(),
                                success:function (data) {
                                    if(data.state==1){
                                        $(".modal-body").html("<p>注册成功</p>");
                                        $("#msg").modal(true);
                                        location.href="/user.html"
                                    }else if(data.state==-2){
                                        $(".modal-body").html("<p>验证码错误，或验证码已经失效</p>");
                                        $("#msg").modal(true);
                                    }else{
                                        $(".modal-body").html("<p>用户名已经被使用</p>");
                                        $("#msg").modal(true);
                                    }
                                    return false;
                                }
                            });
                        }else{
                            $(".modal-body").html("<p>验证码不能为空</p>");
                            $("#msg").modal(true);
                        }
                    }else{
                        $(".modal-body").html("<p>邮箱验证码不能为空</p>");
                        $("#msg").modal(true);
                    }
                }else{
                    $(".modal-body").html("<p>账号和密码不能为空</p>");
                    $("#msg").modal(true);
                }
            });
        });

    </script>
    
    
</head>

<body class="login-page sidebar-collapse">
    <!-- Navbar -->
    <nav class="navbar navbar-expand-lg bg-primary fixed-top navbar-transparent " color-on-scroll="400">
        <div class="container">
            <div class="dropdown button-dropdown">
                <a href="#pablo" class="dropdown-toggle" id="navbarDropdown" data-toggle="dropdown">
                    <span class="button-bar"></span>
                    <span class="button-bar"></span>
                    <span class="button-bar"></span>
                </a>
                <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                    <a class="dropdown-header">Dropdown header</a>
                    <a class="dropdown-item" href="#">Action</a>
                    <a class="dropdown-item" href="#">Another action</a>
                    <a class="dropdown-item" href="#">Something else here</a>
                    <div class="dropdown-divider"></div>
                    <a class="dropdown-item" href="#">Separated link</a>
                    <div class="dropdown-divider"></div>
                    <a class="dropdown-item" href="#">One more separated link</a>
                </div>
            </div>
            <div class="navbar-translate">
                <a class="navbar-brand" href="#" rel="tooltip" data-placement="bottom">
                    Now Ui Kit
                </a>
                <button class="navbar-toggler navbar-toggler" type="button" data-toggle="collapse" data-target="#navigation" aria-controls="navigation-index" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-bar bar1"></span>
                    <span class="navbar-toggler-bar bar2"></span>
                    <span class="navbar-toggler-bar bar3"></span>
                </button>
            </div>
        </div>
    </nav>
    <!-- End Navbar -->
    <!--这里可以调节背景滤纸颜色-->
    <div class="page-header" filter-color="grey">
        <!--这里调节背景图片-->
        <div class="page-header-image" style="background-image:url(/assets/img/login.jpeg)"></div>
        <div class="container">
            <div class="col-md-4 content-center">
                <div class="card card-login card-plain">
                    <form class="form" method="" action="">
                        <div class="header header-primary text-center">
<!--                            logo图片-->
                            <div class="logo-container">
                                <img src="/assets/img/now-logo.png" alt="">
                            </div>
                        </div>
                        <div class="content">
                            <div class="input-group form-group-no-border input-lg">
                                <span class="input-group-addon">
                                    <i class="now-ui-icons users_circle-08"></i>
                                </span>
                                <input required="required"  name="realname" type="text" class="form-control" placeholder="游戏名称">
                            </div>
                            <div style="width: 100%" class="input-group form-group-no-border input-lg">
                                <span class="input-group-addon">
                                    <i class="now-ui-icons ui-1_email-85"></i>
                                </span>
                                <input required="required"  name="email" type="email" class="form-control" placeholder="邮箱">
                                <button id="getCode" class="btn btn-primary btn-round btn-sm" >获取验证码</button>
                            </div>
                            <div style="width: 50%" class="input-group form-group-no-border input-lg">
                                <span class="input-group-addon">
                                    <i class="now-ui-icons text_caps-small"></i>
                                </span>
                                <input required="required"  name="code" placeholder="验证码" class="form-control" />
                            </div>
                            <div class="input-group form-group-no-border input-lg">
                                <span class="input-group-addon">
                                    <i class="now-ui-icons ui-1_lock-circle-open"></i>
                                </span>
                                <input required="required"  name="password" type="password" placeholder="密码" class="form-control" />
                            </div>
                        </div>
                        <div class="footer text-center">
                            <input id="reg" type="button" class="btn btn-primary btn-round btn-lg btn-block" value="注册">
                        </div>
                        <div class="pull-left">
                            <h6>
                                <a href="/login.html" class="link">已有账号？去登陆</a>
                            </h6>
                        </div>
                        <div class="pull-right">
                            <h6>
                                <a href="#pablo" class="link">需要帮助？</a>
                            </h6>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <footer class="footer">
            <div class="container">
                <nav>
                    <ul>
                        <li>
                            <a href="#">
                                我的世界论坛BBS
                            </a>
                        </li>
                        <li>
                            <a href="#">
                                百度
                            </a>
                        </li>
                        <li>
                            <a href="#">
                                谷歌
                            </a>
                        </li>
                        <li>
                            <a href="#">
                                必应
                            </a>
                        </li>
                    </ul>
                </nav>
                <div class="copyright">
                    <p>2020/2/9  冷眸</p>

                </div>
            </div>
        </footer>
    </div>
    <!-- 拟态提示框 -->
    <div class="modal fade" id="msg" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">温馨提示：</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">了解</button>
                    <!--<button type="button" class="btn btn-primary">完成</button>-->
                </div>
            </div>
        </div>
    </div>
</body>


</html>